
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        12/26/2008
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteNewsBUL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MCWEBSITE.DAL;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.BUL
{
    public class websiteNewsBUL
    {
        public static int Save(websiteNewsInfo _websiteNewsInfo)
        {
            try
            {
                if (_websiteNewsInfo.NewsID == 0)
                {
                    return websiteNewsDAL.Insert(_websiteNewsInfo);
                }
                else
                {
                    return websiteNewsDAL.Update(_websiteNewsInfo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error on insert theme : {0}", ex.Message));
            }
        }

        public static int Remove(int _NewsID)
        {
            try
            {
                return websiteNewsDAL.Delete(_NewsID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error on delete Theme : {0}", ex.Message));
            }
        }

        public static int InsertResource(int NewsId, string Resources)
        {
            try
            {
                return websiteNewsDAL.InsertResource(NewsId, Resources);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static int publish(int NewsId)
        {
            try
            {
                return websiteNewsDAL.publish(NewsId);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static int unpublish(int NewsId)
        {
            try
            {
                return websiteNewsDAL.unpublish(NewsId);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static int SaveComposeResource(websiteNewsInfo objInfo, string ApplicationName)
        {
            objInfo.NewsContent = ConvertHelper.ConvertImgString(ApplicationName, objInfo.NewsContent, objInfo.CreatDate.ToString("yyyy-MM-dd").Replace('-', '_'), objInfo.NewsID);
            return websiteNewsDAL.SaveComposeResource(objInfo);
        }

        public static DataSet GetNewsWithFilter(string NewsId, string Title, string CreateDate, string status)
        {
            try
            {
                return websiteNewsDAL.GetNewsWithFilter(NewsId, Title, CreateDate, status);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static DataSet GetNewsWithFilterLanguage(string NewsId, string Title, string CreateDate, string status, string strLanguage)
        {
            try
            {
                return websiteNewsDAL.GetNewsWithFilterLanguage(NewsId, Title, CreateDate, status, strLanguage);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static string GetCreateDate(int NewsId)
        {
            try
            {
                websiteNewsInfo objNewsInfo = websiteNewsDAL.SelectOne(NewsId);
                return objNewsInfo.CreatDate.ToString("yyyy-MM-dd").Replace("-", "_");
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteNewsInfo> GetAll()
        {
            try
            {
                return websiteNewsDAL.SelectAll();
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteNewsInfo> GetByLanguageCode(string LanguageCode)
        {
            try
            {
                return websiteNewsDAL.SelectByLanguage(LanguageCode);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static DataSet SelectNtoMByLanguage(int N, int M, string LanguageCode)
        {
            try
            {
                return websiteNewsDAL.SelectNtoMByLanguage(N, M, LanguageCode);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteNewsInfo> SelectNtoMByLanguageByCat(int N, int M, string LanguageCode, int CatID)
        {
            try
            {
                return websiteNewsDAL.SelectNtoMByLanguageByCat(N, M, LanguageCode, CatID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static DataSet SelectNtoMByLanguageByCatDS(int N, int M, string LanguageCode, int CatID)
        {
            try
            {
                return websiteNewsDAL.SelectNtoMByLanguageByCatDS(N, M, LanguageCode, CatID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }
        public static DataSet SelectNtoMByLanguageByCatByNewsIdDS(int N, int M, string LanguageCode, int CatID, int NewsId)
        {
            try
            {
                return websiteNewsDAL.SelectNtoMByLanguageByCatByNewsIdDS(N, M, LanguageCode, CatID, NewsId);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static DataSet getByCat(string LanguageCode, int CatID)
        {
            try
            {
                return websiteNewsDAL.getByCat(LanguageCode, CatID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static DataSet GetByLanguageByNewsID(string LanguageCode, int NewsID)
        {
            try
            {
                return websiteNewsDAL.GetByLanguageByNewsID(LanguageCode, NewsID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static websiteNewsInfo Load(int _NewsID)
        {
            try
            {
                return websiteNewsDAL.SelectOne(_NewsID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteNewsInfo> Search()
        {
            try
            {
                return websiteNewsDAL.SelectFilters();
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }
    }
}

